#ifndef _BANG_WINDOW_H_
#define _BANG_WINDOW_H_


#define WINDOW_INVISIBLE(w) \
    ((w)->attrib.map_state != IsViewable                    || \
     (!(w)->damaged)                                        || \
     (w)->attrib.x + (w)->width  + (w)->output.right  <= 0  || \
     (w)->attrib.y + (w)->height + (w)->output.bottom <= 0  || \
     (w)->attrib.x - (w)->output.left >= (w)->screen->width || \
     (w)->attrib.y - (w)->output.top >= (w)->screen->height)

typedef struct _CompWindowExtents {
   int left;
   int right;
   int top;
   int bottom;
} CompWindowExtents;

struct _CompWindow {
   CompScreen       *screen;
   Ecore_X_Window    id;
   char             *name;
   Window            frame;
   unsigned int      mapNum;
   XWindowAttributes attrib;
   Ecore_X_Window_Attributes e_attrib;
   int               serverX;
   int               serverY;
   Pixmap            pixmap;
   CompTexture       texture;
   CompMatrix        matrix;
   Damage            damage;
   Bool              alpha;
   GLint             width;
   GLint             height;
   Region            region;
   Region            clip;

   int        showed;
   Bool       shaded;
   Bool       invisible;
   Bool       destroyed;
   Bool       damaged;
   Bool       redirected;
   int        destroyRefCnt;
   int        unmapRefCnt;

   GLushort opacity;
   GLushort brightness;
   GLushort saturation;

   WindowPaintAttrib   paint;
   Bool                scaled;

   CompWindowExtents input;
   CompWindowExtents output;

   XRectangle *damageRects;
   int         sizeDamage;
   int         nDamage;

   GLfloat  *vertices;
   int       vertexSize;
   GLushort *indices;
   int       indexSize;
   int       vCount;
   int       texUnits;

   CompPrivate *privates;
};

int
allocateWindowPrivateIndex (CompScreen *screen);

void
freeWindowPrivateIndex (CompScreen *screen,
                        int         index);

void
updateWindowRegion (CompWindow *w);

CompWindow *
addWindow (CompScreen *screen,
           Window      id,
           Window      aboveId);

void
removeWindow (CompWindow *w);

void
destroyWindow (CompWindow *w);

void
mapWindow (CompWindow *w);

void
unmapWindow (CompWindow *w);

void
bindWindow (CompWindow *w);

void
releaseWindow (CompWindow *w);

void
moveWindow (CompWindow *w,
            int         dx,
            int         dy,
            Bool        damage,
            Bool        immediate);

Bool
resizeWindow (CompWindow *w,
              int         x,
              int         y,
              int         width,
              int         height,
              int         borderWidth);

void
addWindowDamage (CompWindow *w);

Bool
damageWindowRect (CompWindow *w,
                  Bool        initial,
                  BoxPtr      rect);

void
damageWindowRegion (CompWindow *w,
                    Region      region);

void
setWindowScale (CompWindow *w,
                float       xScale,
                float       yScale);

void
unredirectWindow (CompWindow *w);

void
redirectWindow (CompWindow *w);

int
restackWindow (CompWindow *w, Ecore_X_Window aboveId);

Ecore_X_Window_Type
composite_win_determine_type(Ecore_X_Window w);



#endif
